import myJdkProxy.ProxyUtil;
import staticProxy.extendsWay.UserServiceClass;
import staticProxy.juheWay.LogProxy;
import staticProxy.juheWay.UserService;
import staticProxy.juheWay.UserServiceImpl;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InvocationTargetException, InstantiationException, NoSuchMethodException, IllegalAccessException {
        //聚合方式静态代理
        UserService userService = new LogProxy(new UserServiceImpl());
        userService.doWork();

        System.out.println(">>>>>>>>>>>>>>>>>>>");
        //继承方式静态代理
        UserServiceClass userServiceClass = new staticProxy.extendsWay.LogProxy();
        userServiceClass.doWork();

        System.out.println(">>>>>>>>>>>>>>>>>>>");
        //测试JDK动态代理
        JdkProxy.UserService u1 = (JdkProxy.UserService) new JdkProxy.LogProxy(new JdkProxy.UserServiceImpl()).getTarget();
        u1.doWork();

        System.out.println(">>>>>>>>>>>>>>>>>>>");
        //测试自己写的动态代理类
        //myJdkProxy.UserService u3 = (myJdkProxy.UserService) ProxyUtil.newProxyInstance(new myJdkProxy.UserServiceImpl());
       // ProxyUtil.newProxyInstance(new myJdkProxy.UserServiceImpl());
       UserService u = (UserService) ProxyUtil.newProxyInstance(new myJdkProxy.UserServiceImpl());
       u.doWork();
    }
}
